package com.springapp.db.util;

import com.springapp.mvc.entity.Post;
import com.springapp.mvc.entity.User;

import java.util.Date;

/**
 * Created by Dima on 10.01.2015.
 */
public class PostBuilder {

    private Long userId;
    private Date dateCreated;
    private String text;

    public static PostBuilder aPost(){
        return new PostBuilder();
    }

    public PostBuilder withText(String text){
        this.text = text;
        return this;
    }

    public PostBuilder postedOn(Date dateCreated){
        this.dateCreated = dateCreated;
        return this;
    }

    public PostBuilder fromUser(User user){
        this.userId = user.getId();
        return this;
    }

    public PostBuilder fromUser(Long userId){
        this.userId = userId;
        return this;
    }

    public Post build(){
        Post p = new Post();
        p.setUserId(userId);
        p.setDateCreated(dateCreated);
        p.setPostText(text);
        return p;
    }

}
